<style>
  .layui-form-label.required:before {
    /* 这种写法也可以*/
    content: " *";
    color: red;
  }
  .open-form .layui-form-label {
    width: 110px;
  }
  .open-form .layui-input-block {
    margin-left: 140px;
  }
</style>

<!-- bom表格操作列 -->
<script type="text/html" id="bomProductPlanningTableBar">
  <!-- {{# if(d.assemblyNature != '3'){ }} -->
  <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="addDownInfo"
    >添加下级Bom</a
  >
  <!-- {{#}}} -->
  <!--    {{# if(d.assemblyNature == '3'){ }}-->
  <!--    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="blueprints">图纸管理</a>-->
  <!--    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="processRoute">工艺路线</a>-->
  <!--    {{#}}}-->
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="removeInfo"
    >移除</a
  >
</script>
<script type="text/html" id="skuSelectDiv">
  <div style="padding: 10px;position: relative;">
    <table
      class="layui-table"
      id="skuSelectTable"
      lay-filter="skuSelectTable"
    ></table>
    <button
      class="layui-btn"
      style="position: absolute;right: 50px;bottom: -50px;"
      id="skuSelectConfirm"
    >
      确认选择
    </button>
  </div>
</script>

<script
  type="text/javascript"
  src="../../../admin/assets/js/pdfobject.min.js"
></script>
<!-- 表单弹窗 -->
<form lay-filter="proTaskZYForm" class="layui-form proTaskZYForm open-form">
  <div class="open-model" id="proTaskZYFormDiv">
    <div class="open-auto">
      <fieldset class="layui-elem-field layui-field-title">
        <legend>产品信息</legend>
      </fieldset>
      <div class="layui-form-item layui-row">
        <div class="layui-col-md3">
          <label class="layui-form-label required">来源：</label>
          <div class="layui-input-block">
            <input
              name="source"
              disabled
              type="text"
              class="layui-input"
              required
              autocomplete="off"
              value="自研产品"
            />
          </div>
        </div>
        <div class="layui-col-md3">
          <label class="layui-form-label">产品类别：</label>
          <div class="layui-input-block">
            <input
              name="productTypeName"
              disabled
              type="text"
              class="layui-input"
              lay-verify="required"
            />
            <input
              id="productTypeId"
              name="productTypeId"
              type="hidden"
              value="' + d.proTypeId + '"
              lay-verify="required"
            />
          </div>
        </div>
        <div class="layui-col-md3">
          <label class="layui-form-label">产品性质：</label>
          <div class="layui-input-block">
            <input
              name="productNatureName"
              disabled
              type="text"
              class="layui-input"
              lay-verify="required"
            />
          </div>
        </div>
        <div class="layui-col-md3">
          <label class="layui-form-label required">产品属性：</label>
          <div class="layui-input-block">
            <input
              name="assemblyNatureName"
              disabled
              type="text"
              class="layui-input"
              lay-verify="required"
            />
          </div>
        </div>
      </div>
      <div class="layui-form-item layui-row">
        <div class="layui-col-md3">
          <label class="layui-form-label">内部SKU号：</label>
          <div class="layui-input-block" id="SkuInfo">
            <input id="productDetailId" name="productDetailId" type="hidden" />
            <input
              id="inSkuCode"
              name="inSkuCode"
              disabled
              type="text"
              class="layui-input"
              lay-verify="required"
            />
          </div>
        </div>
        <div class="layui-col-md3">
          <label class="layui-form-label">内部SKU名称：</label>
          <div class="layui-input-block">
            <input
              type="text"
              id="inSkuName"
              disabled
              name="inSkuName"
              class="layui-input"
            />
          </div>
        </div>
        <div class="layui-col-md3">
          <label class="layui-form-label">内部规格码：</label>
          <div class="layui-input-block">
            <input
              type="text"
              id="inSkuSpec"
              disabled
              name="inSkuSpec"
              class="layui-input"
            />
          </div>
        </div>
        <div class="layui-col-md3">
          <label class="layui-form-label">基础单位：</label>
          <div class="layui-input-block">
            <input
              name="inUnitName"
              disabled
              type="text"
              class="layui-input"
              lay-verify="required"
            />
          </div>
        </div>
        <!--        <div class="layui-col-md3">-->
        <!--            <label class="layui-form-label">计量单位：</label>-->
        <!--            <div class="layui-input-block">-->
        <!--                <input name="inSkuUnitName" disabled type="text" class="layui-input"-->
        <!--                       lay-verify="required"/>-->
        <!--            </div>-->
        <!--        </div>-->
      </div>

      <div class="layui-form-item layui-row">
        <!--        <div class="layui-col-md3">-->
        <!--            <label class="layui-form-label">基础单位数量：</label>-->
        <!--            <div class="layui-input-block">-->
        <!--                <input type="text" disabled id="inUnitCount" name="inUnitCount" class="layui-input">-->
        <!--            </div>-->
        <!--        </div>-->
        <div class="layui-col-md3">
          <label class="layui-form-label required">计量方式(主)：</label>
          <div class="layui-input-block">
            <input
              type="text"
              id="mainCalWayName"
              readonly="readonly"
              name="mainCalWayName"
              class="layui-input"
            />
          </div>
        </div>
        <div class="layui-col-md3">
          <label class="layui-form-label required">包装单位(主)：</label>
          <div class="layui-input-block">
            <input
              type="text"
              id="mainUnitName"
              readonly="readonly"
              name="mainUnitName"
              class="layui-input"
            />
          </div>
        </div>
        <div class="layui-col-md3">
          <label class="layui-form-label required">换算率(主)：</label>
          <div class="layui-input-block">
            <input
              type="text"
              id="mainUnitRate"
              readonly="readonly"
              name="mainUnitRate"
              class="layui-input"
            />
          </div>
        </div>
        <div class="layui-col-md3">
          <label class="layui-form-label">计量方式(辅)：</label>
          <div class="layui-input-block">
            <input
              type="text"
              id="subCalWayName"
              readonly="readonly"
              name="subCalWayName"
              class="layui-input"
            />
          </div>
        </div>
      </div>
      <div class="layui-form-item layui-row">
        <div class="layui-col-md3">
          <label class="layui-form-label">计量单位(辅)：</label>
          <div class="layui-input-block">
            <input
              type="text"
              id="subUnitName"
              readonly="readonly"
              name="subUnitName"
              class="layui-input"
            />
          </div>
        </div>
        <div class="layui-col-md3">
          <label class="layui-form-label">换算率(辅)：</label>
          <div class="layui-input-block">
            <input
              type="text"
              id="subUnitRate"
              readonly="readonly"
              name="subUnitRate"
              class="layui-input"
            />
          </div>
        </div>
        <div class="layui-col-md3">
          <label class="layui-form-label">成本核算类型：</label>
          <div class="layui-input-block">
            <select
              id="costCheckType"
              disabled
              name="costCheckType"
              lay-filter="costCheckType"
              class="layui-input borderNone"
            ></select>
          </div>
        </div>
        <div class="layui-col-md3">
          <label class="layui-form-label">是否质检：</label>
          <div class="layui-input-block">
            <select
              id="checkStatus"
              disabled
              name="checkStatus"
              lay-filter="checkStatus"
              class="layui-input borderNone"
            ></select>
          </div>
        </div>
      </div>
      <div class="layui-form-item layui-row">
        <div class="layui-col-md3">
          <label class="layui-form-label">是否料箱管理：</label>
          <div class="layui-input-block">
            <select
              id="boxStatus"
              disabled
              name="boxStatus"
              lay-filter="boxStatus"
              class="layui-input borderNone"
            ></select>
          </div>
        </div>
        <div class="layui-col-md3">
          <label class="layui-form-label">说明：</label>
          <div class="layui-input-block">
            <input
              type="text"
              id="inRemark"
              name="inRemark"
              class="layui-input"
            />
          </div>
        </div>
      </div>
      <fieldset class="layui-elem-field layui-field-title">
        <legend>其他信息</legend>
      </fieldset>
      <div class="layui-form-item layui-row">
        <div class="layui-tab" lay-filter="test-handle" lay-allowclose="true">
          <ul class="layui-tab-title">
            <li class="layui-this" lay-id="YSBZ">产品验收标准</li>
            <li lay-id="BOMGUIHUA">MRP物料BOM规划</li>
            <li lay-id="GCGUIHUA" class="layui-this">产品工程规划</li>
          </ul>
          <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
              <div class="layui-form-item layui-row">
                <label class="layui-form-label">版本编号：</label>
                <input
                  style="border: none"
                  type="text"
                  value="BCZ380C9.2.1.4.1.1.1-2"
                  disabled
                  id="infoVersion"
                  name="infoVersion"
                  class="layui-input"
                />
              </div>
              <div class="layui-form-item layui-row">
                <div class="layui-col-md5">
                  <div
                    id="TuZhiPdf"
                    style="height: 100%; margin-left: 10px"
                  ></div>
                </div>
                <div class="layui-col-md7">
                  <div class="layui-form-item layui-row">
                    <button
                      type="button"
                      id="addTestItem"
                      class="layui-btn"
                      lay-filter="addTestItem"
                      lay-submit
                    >
                      添加检测项
                    </button>
                    <table
                      class="layui-table"
                      id="testItemTable"
                      lay-filter="testItemTable"
                    ></table>
                  </div>
                  <div class="layui-form-item text-right">
                    <button
                      class="layui-btn"
                      lay-filter="saveTestItem"
                      type="button"
                      id="saveTestItem"
                    >
                      保存检测项
                    </button>
                  </div>
                </div>
              </div>
            </div>
            <div class="layui-tab-item" id="bom_info">
              <div class="layui-form-item layui-row">
                <div class="layui-form-item layui-row">
                  <button
                    type="button"
                    id="addBomSKu"
                    class="layui-btn"
                    lay-filter="addBomSKu"
                    lay-submit
                  >
                    添加子件物料
                  </button>
                  <table
                    class="layui-table"
                    id="bomTreeTableInfo"
                    lay-filter="bomTreeTableInfo"
                  ></table>
                </div>
              </div>
            </div>
            <div class="layui-tab-item" id="gy" layui-show>
              <!-- <div class="layui-form-item layui-row">
                <div class="layui-col-md3">
                  <label class="layui-form-label">选择主材：</label>
                  <div class="layui-input-block">
                    <select id="mainSkuId" lay-search="" name="mainSkuId" lay-filter="mainSkuId" class="common-select-search"></select>
                  </div>
                </div>
              </div> -->
              <div class="layui-form-item layui-row">
                <div class="layui-col-md3">
                  <label class="layui-form-label">选择工艺路线：</label>
                  <div class="layui-input-block">
                    <select
                      id="processLineTemplate"
                      lay-search=""
                      name="processLineTemplate"
                      lay-filter="processLineTemplate"
                      class="common-select-search"
                    ></select>
                  </div>
                </div>
              </div>
              <!-- <div class="layui-form-item layui-row">
                <div class="layui-col-md3">
                  <label class="layui-form-label">关联模具图纸：</label>
                  <div class="layui-input-block">
                    <select id="isRelevance" name="isRelevance" lay-filter="isRelevance" class="common-select-search">
                      <option value="0">不关联</option>
                      <option value="1">关联模具图纸</option>
                    </select>
                  </div>
                </div>
                <div class="layui-col-md9" id="moldUploadInfo">
                  <div class="layui-col-md4">
                    <label class="layui-form-label">模具图纸：</label>
                    <div class="layui-input-block">
                      <div id="fileUploadMoldBtn" class="layui-btn" style="float: left; margin-left: 3px">
                        <i class="layui-icon">&#xe681;</i>
                        上传文件
                      </div>
                      <br />
                      <div id="addMoldHeaderPdf" style="margin-top: -16px" class="companyFormPhotos"></div>
                      <input name="attachmentMoldPdf" id="attachmentMoldPdf" type="hidden" class="layui-input" />
                    </div>
                  </div>
                  <div class="layui-col-md7">
                    <label class="layui-form-label">模具图纸备注：</label>
                    <div class="layui-input-block">
                      <textarea id="moldRemark" name="moldRemark" placeholder="模具图纸备注" class="layui-textarea" autocomplete="off" />
                    </div>
                  </div>
                </div>
              </div> -->
              <div class="layui-form-item layui-row">
                <div class="layui-col-md4">
                  <div
                    style="
                      padding: 0 10px;
                      display: flex;
                      justify-content: space-between;
                      align-items: center;
                    "
                  >
                    <h2>工序管理</h2>
                    <button
                      type="button"
                      id="addProcessOne"
                      class="layui-btn"
                      lay-filter="addProcessOne"
                      lay-submit
                    >
                      添加工序
                    </button>
                  </div>
                  <table
                    class="layui-table"
                    id="productProjectTable"
                    lay-filter="productProjectTable"
                  ></table>
                </div>
                <div class="layui-col-md4" style="padding: 0 15px">
                  <form
                    lay-filter="processForm"
                    id="processForm"
                    class="layui-form"
                  >
                    <div style="margin-bottom: 10px; margin-left: 5px">
                      <h2>工艺参数</h2>
                    </div>
                    <div id="processFormContent">
                      <div class="layui-form-item">
                        <label class="layui-form-label">工序内容</label>
                        <div class="layui-input-block">
                          <textarea
                            name="content"
                            placeholder="请输入工艺参数"
                            class="layui-input"
                          />
                        </div>
                      </div>
                      <div class="layui-form-item">
                        <label class="layui-form-label">夹具</label>
                        <div class="layui-input-block">
                          <input
                            type="text"
                            name="fixture"
                            placeholder="请输入夹具"
                            class="layui-input"
                          />
                        </div>
                      </div>
                      <div class="layui-form-item">
                        <label class="layui-form-label">量具</label>
                        <div class="layui-input-block">
                          <input
                            type="text"
                            name="measuringTools"
                            placeholder="请输入量具"
                            class="layui-input"
                          />
                        </div>
                      </div>
                      <div class="layui-form-item">
                        <label class="layui-form-label">报工单位</label>
                        <div class="layui-input-block">
                          <input
                            type="text"
                            name="unitId"
                            placeholder="请输入报工单位"
                            class="layui-input"
                          />
                        </div>
                      </div>
                      <div class="layui-form-item">
                        <label class="layui-form-label">工时定额(分钟)</label>
                        <div class="layui-input-block">
                          <input
                            type="text"
                            name="hoursQuota"
                            placeholder="请输入工时定额"
                            class="layui-input"
                          />
                        </div>
                      </div>
                      <div class="layui-form-item">
                        <label class="layui-form-label">工资定额(元)</label>
                        <div class="layui-input-block">
                          <input
                            type="text"
                            name="salaryQuota"
                            placeholder="请输入工资定额"
                            class="layui-input"
                          />
                        </div>
                      </div>
                      <div class="layui-form-item">
                        <label class="layui-form-label">NG工资定额</label>
                        <div class="layui-input-block">
                          <input
                            type="text"
                            name="ngSalaryQuota"
                            placeholder="请输入NG工资定额"
                            class="layui-input"
                          />
                        </div>
                      </div>
                    </div>
                  </form>
                </div>
                <div class="layui-col-md4">
                  <div
                    style="
                      padding: 0 10px;
                      display: flex;
                      justify-content: space-between;
                      align-items: center;
                    "
                  >
                    <h2>关联物料</h2>
                    <button type="button" id="addSku" class="layui-btn">
                      添加物料
                    </button>
                  </div>
                  <table
                    class="layui-table"
                    id="skuTable"
                    lay-filter="skuTable"
                  ></table>
                </div>
              </div>
              <div class="layui-form-item text-right">
                <button
                  class="layui-btn"
                  lay-filter="saveProductProject"
                  type="button"
                  id="saveProjectUp"
                >
                  保存产品规划
                </button>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="layui-form-item text-right">
      <button
        class="layui-btn layui-btn-normal"
        id="submitProofread"
        type="button"
      >
        提交校对
      </button>
      <button
        class="layui-btn layui-btn-primary"
        type="button"
        ew-event="closeDialog"
      >
        关闭
      </button>
    </div>
  </div>
</form>

<script type="text/html" id="viewAttachmentHtml">
  <div id="example" style="height: 100%;"></div>
</script>

<script type="text/html" id="viewAttachmentHtml2">
  <form
    lay-filter="imgModifyForm"
    class="layui-form model-form"
    style="padding: 5px 30px 0 30px;height: calc(100% - 5px);overflow: hidden;"
  >
    <div class="open-details-box" style="height: calc(100% - 75px);">
      <div class="layui-row table-bor " style="margin-top: 15px;">
        <div class="layui-form-item layui-row">
          <label class="layui-form-label required">产品图纸：</label>
          <div class="layui-input-block">
            <div id="example1" class="uploadImgStyle"></div>
            <div id="productPicBtn" class="layui-btn" style="float: left;">
              <i class="layui-icon">&#xe681;</i>
              上传新图纸
            </div>
            <input
              name="productPic"
              type="hidden"
              class="layui-input"
              lay-verify=""
              id="productPic"
            />
          </div>
        </div>
        <div class="layui-form-item layui-row">
          <div class="layui-col-md12">
            <label class="layui-form-label required">工艺说明：</label>
            <div class="layui-input-block">
              <textarea
                id="processDescription"
                name="processDescription"
                placeholder="工艺说明"
                class="layui-textarea"
                autocomplete="off"
              />
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="layui-form-item text-right">
      <button
        class="layui-btn layui-btn-primary"
        type="button"
        ew-event="closeDialog"
      >
        取消
      </button>
      <button
        class="layui-btn"
        lay-filter="imgModifyFormSubmit"
        lay-submit
        type="button"
      >
        保存
      </button>
    </div>
  </form>
</script>

<!-- 质检表格操作列 -->
<script type="text/html" id="testItemTableBar">
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delTestItem"
    >删除</a
  >
</script>

<!-- 表格操作列 -->
<script type="text/html" id="productProcessTableBar">
  <!-- <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="checkSku">选择成品</a> -->

  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delProcess"
    >删除</a
  >
</script>

<!-- skuTableBar -->
<script type="text/html" id="skuTableBar">
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<!-- js部分 -->
<script>
  layui.use(
    [
      "layer",
      "form",
      "tableTreeDj",
      "table",
      "laydate",
      "admin",
      "laytpl",
      "upload",
      "config",
      "element",
    ],
    function () {
      var $ = layui.jquery;
      var layer = layui.layer;
      var config = layui.config;
      var upload = layui.upload;
      var table = layui.table;
      var admin = layui.admin;
      var form = layui.form;
      var laydate = layui.laydate;
      var element = layui.element;
      var tableTree = layui.tableTreeDj;

      let projectTableData = [];
      //初始化data
      let testItemData = [];
      let moldName = "";
      let customerName = "";
      let fileName = "";
      let tzId;
      let tzVersion;
      let data = admin.getTempData("resProTaskZYData");
      let bom_tab = document.querySelector(".layui-tab-title li:nth-child(2)");
      let bom_content = document.querySelector(
        ".layui-tab-content .layui-tab-item:nth-child(2)"
      );
      let gx_tab = document.querySelector(".layui-tab-title li:nth-child(3)");
      let gx_content = document.querySelector(
        ".layui-tab-content .layui-tab-item:nth-child(3)"
      );
      const nowData = { ...parentData };
      console.log("data", data);

      if (nowData.eventName === "detail") {
        admin.setFormDisable("#proTaskFormDiv", true);
        admin.setFormDisable("#proTaskZYFormDiv", true);
        $("#submitProofread").hide();
        $("#addProcessOne").hide();
        $("#saveProjectUp").hide();
        $("#addBomSKu").hide();
      }
      if (nowData.type == "bom") {
        element.tabDelete("test-handle", "YSBZ");
        element.tabDelete("test-handle", "GCGUIHUA");
        element.tabChange("test-handle", "BOMGUIHUA");
        $("#submitProofread").hide();
      } else if (nowData.type == "process") {
        element.tabDelete("test-handle", "YSBZ");
        element.tabDelete("test-handle", "BOMGUIHUA");
        element.tabChange("test-handle", "GCGUIHUA");
        $("#saveProjectUp").hide();
      }
      laydate.render({
        elem: "#planGivenTime",
        type: "datetime",
      });

      /**
       * 初始化任务详情
       */
      let reqUrl = "";
      if (nowData.type == "process" && data.taskId) {
        reqUrl =
          "enterprise/res/admin/echnologyParamRecord/detail/" +
          data.taskId +
          "/" +
          data.id;
      } else {
        reqUrl = "enterprise/res/admin/planning/proTask/detail/" + data.id;
      }
      admin.req(reqUrl, {}, function (res) {
        if (res.code == 200) {
          let dataValue = res.data === undefined ? null : res.data;
          if (dataValue.processProjectData.length > 0) {
            dataValue.processLineTemplate =
              dataValue.processProjectData[0].templateId;
          }
          form.val("proTaskZYForm", dataValue);
          admin.initDataSelect(
            "enterprise/product/admin/processLineTemplate/list?page=1&limit=999",
            {},
            "processLineTemplate",
            dataValue.processLineTemplate
              ? dataValue.processLineTemplate
              : null,
            "模板",
            "name",
            "id"
          );

          admin.getDictList(
            "costCheckType",
            "product_detail_cost_check_type",
            res.data.costCheckType === null ? null : res.data.costCheckType,
            "成本核算"
          );
          admin.getDictList(
            "checkStatus",
            "sys_yes_no",
            res.data.checkStatus === null ? null : res.data.checkStatus,
            "是否质检"
          );
          admin.getDictList(
            "boxStatus",
            "sys_yes_no",
            res.data.boxStatus === null ? null : res.data.boxStatus,
            "是否料箱管理"
          );

          projectTableData = res.data.processProjectData;
          testItemData = res.data.testItemData;
          if (res.data.drawInfo) {
            tzId = res.data.drawInfo.id;
            tzVersion = res.data.drawInfo.versionName;
          }
          let name = res.data.cusProductFigure;
          let imagUrl = "";
          //初始化文件
          $("#addHeaderPdf").html(
            '<div class="attachments">' +
              '<div><img name="attachments" src="../../../admin/assets/images/attachmentsIcon/pdf.png"><span class="file-a">' +
              name +
              "</span></div></div>"
          );
          $("#attachmentPdf").val(res.data.attachmentPdfUrl);
          imagUrl = res.data.attachmentPdfUrl;
          $("#fileName").text(res.data.cusProductFigure);
          $(".attachments").click(function () {
            let json = {};
            json.attachment = imagUrl;
            showViewAttachmentModel(json);
          });
          if (imagUrl && imagUrl.indexOf(".pdf") !== -1) {
            PDFObject.embed(imagUrl, "#TuZhiPdf");
          } else {
            let attachmentHtml = "";
            imagUrl.split(",").forEach((attachmentUrl, index) => {
              attachmentHtml +=
                '<div><div><img style="max-width:620px" src="' +
                attachmentUrl +
                '"></div></div>';
            });
            $("#TuZhiPdf").html(attachmentHtml);
          }

          $("#TuZhiPdf").click(function () {
            let json = {};
            json.attachment = imagUrl;
            json.remark = res.data.drawInfo.remark;
            json.taskId = res.data.id;
            json.drawId = res.data.drawInfo.id;
            showViewAttachmentModel2(json);
          });

          //是否关联图纸的点击
          form.on("select(isRelevance)", function (data) {
            console.log("data", data);
            if (data.value === "1") {
              $("#moldUploadInfo").show();
            } else {
              $("#moldUploadInfo").hide();
            }
          });

          //默认隐藏
          if (res.data.drawInfo) {
            let drawInfos = res.data.drawInfo;
            if (res.data.drawInfo.isRelevance === "1") {
              $("#moldUploadInfo").show();
              $("#addMoldHeaderPdf").html(
                '<div class="moldAttachments">' +
                  '<div><img name="moldAttachments" src="../../../admin/assets/images/attachmentsIcon/pdf.png"><span class="file-a">' +
                  res.data.drawInfo.moldDrawInfo.name +
                  "</span></div></div>"
              );
              $("#attachmentMoldPdf").val(
                res.data.drawInfo.moldDrawInfo.fileUrl
              );
              $("#moldRemark").val(res.data.drawInfo.moldDrawInfo.remark);
              moldName = res.data.drawInfo.moldDrawInfo.name;
              $(".moldAttachments").click(function () {
                let json = {};
                json.attachment = res.data.drawInfo.moldDrawInfo.fileUrl;
                showViewAttachmentModel(json);
              });
            } else {
              $("#moldUploadInfo").hide();
            }
            $("#isRelevance").val(res.data.drawInfo.isRelevance);

            /**
             *  初始化sku主材
             */
            admin.initDataSelectAndMap(
              "enterprise/product/admin/productDetailWMS/list",
              { categoryType: "production", limit: 9999 },
              "mainSkuId",
              drawInfos.mainSkuId == null ? null : drawInfos.mainSkuId,
              "SKU物料",
              "codeAndName",
              null,
              null
            );
          } else {
            $("#moldUploadInfo").hide();
          }

          //初始化工序productProjectTable
          table.render({
            elem: "#productProjectTable",
            data: projectTableData,
            id: "productProjectTable",
            limit: 9999,
            initSort: {
              field: "sorted", // 按 id 字段排序
              type: "asc", // 升序排序
            },
            cols: [
              [
                { type: "numbers", title: "序号" },
                {
                  field: "name",
                  align: "center",
                  title: "工序名称",
                  templet: admin.setTableInput(
                    "name",
                    nowData.eventName === "detail",
                    "name"
                  ),
                },
                {
                  field: "sorted",
                  title: "工序号",
                  templet: admin.setTableInput(
                    "sorted",
                    nowData.eventName === "detail",
                    "sorted"
                  ),
                },
                {
                  field: "proCode",
                  title: "工序编码",
                  templet: admin.setTableInput("proCode", true, "proCode"),
                },
                { field: "sorted", title: "工序排序", hide: true },
                { field: "content", title: "工序工艺要求", hide: true },
                { field: "fixture", title: "夹具", hide: true },
                { field: "measuringTools", title: "量具", hide: true },
                { field: "hoursQuota", title: "工时定额(分钟)", hide: true },
                { field: "salaryQuota", title: "工资定额(元)", hide: true },
                // { field: 'proCode', sort: true, title: '产品工序编码', templet: admin.setTableInput('proCode', nowData.eventName === 'detail') },
                // { field: 'sorted', sort: true, title: '工序排序', templet: admin.setTableInput('sorted', nowData.eventName === 'detail') },
                // { field: 'content', sort: true, title: '工序工艺要求', templet: admin.setTableInput('content', nowData.eventName === 'detail') },
                // { field: 'fixture', sort: true, title: '夹具', templet: admin.setTableInput('fixture', nowData.eventName === 'detail') },
                // { field: 'measuringTools', sort: true, title: '量具', templet: admin.setTableInput('measuringTools', nowData.eventName === 'detail') },
                // { field: 'hoursQuota', sort: true, title: '工时定额(分钟)', templet: admin.setTableInput('hoursQuota', nowData.eventName === 'detail') },
                // { field: 'salaryQuota', sort: true, title: '工资定额(元)', templet: admin.setTableInput('salaryQuota', nowData.eventName === 'detail') },
                // { field: 'productDetailId', sort: true, title: '成品料号', templet: admin.setTableInput('productDetailId', true) },
                // { field: 'qualityParam', edit: 'text', sort: true, title: '工序质检要求' },
                // , {field: 'skuGetCode', edit: 'text', sort: true, title: '领料料号'}
                {
                  align: "center",
                  toolbar: "#productProcessTableBar",
                  hide: nowData.eventName === "detail",
                  title: "操作",
                },
              ],
            ],
            done: function () {
              admin.tableInputChange("productProjectTable");
              projectTableData = table.cache["productProjectTable"];
              // if (projectTableData.length === 0) {

              // } else {
              //   admin.setFormDisable("#processFormContent", false);
              //   $("#addSku").show();
              // }
              admin.tableInputChangeByClass(
                "productProjectTable",
                "sorted",
                (index) => {
                  let name = $("#inSkuName").val();
                  let sorted = projectTableData[index].sorted;
                  let proCode = name + "-" + sorted;
                  table.cache["productProjectTable"][index].proCode = proCode;
                  admin.setTableColHtml(
                    "productProjectTable",
                    index,
                    "proCode",
                    proCode
                  );
                }
              );
            },
          });
          // admin.tableInputChangeByClass("productProjectTable", "name", (index) => {
          //   let name = projectTableData[index].name;
          //   let sorted = projectTableData[index].sorted;
          //   let proCode = name + "-" + sorted;
          //   table.cache["productProjectTable"][index].proCode = proCode;
          //   admin.setTableColHtml("productProjectTable", index, "proCode", proCode);
          // });

          admin.setFormDisable("#processFormContent", true);
          $("#addSku").hide();
          // 行单击事件( 双击事件为: rowDouble )
          let productProjectTableIndex = -1;
          table.on("row(productProjectTable)", function (obj) {
            if ($(event.target).is("input,select,textarea")) {
              return; // 如果是输入框，直接返回，不执行后续代码
            }
            var data = obj.data; // 获取当前行数据
            const index = $(obj.tr[0]).data("index");
            admin.setFormDisable("#processFormContent", false);
            $("#addSku").show();
            productProjectTableIndex = index;
            form.val("proTaskZYForm", {
              content: "",
              fixture: "",
              measuringTools: "",
              unitId: "",
              hoursQuota: "",
              salaryQuota: "",
              ngSalaryQuota: "",
            });
            table.reload("skuTable", {
              data: [],
            });
            form.val("proTaskZYForm", {
              content: data.content,
              fixture: data.fixture,
              measuringTools: data.measuringTools,
              unitId: data.unitId,
              hoursQuota: data.hoursQuota,
              salaryQuota: data.salaryQuota,
              ngSalaryQuota: data.ngSalaryQuota,
            });

            table.reload("skuTable", {
              data: data.versionSkuList || [],
            });
            return false;
          });

          // 监听processForm下面所有input
          $("#processFormContent input,textarea").on("input", function () {
            let list = table.cache["productProjectTable"];
            let name = $(this).attr("name");
            list[productProjectTableIndex][name] = $(this).val();
            table.reload("productProjectTable", { data: list });
          });
          // sku表格
          table.render({
            elem: "#skuTable",
            data: [],
            id: "skuTable",
            cols: [
              [
                { type: "numbers", title: "序号" },
                { field: "skuName", title: "物料名称" },
                { field: "skuCode", title: "物料编码" },
                { field: "skuSpec", title: "物料规格码" },
                {
                  field: "quantity",
                  title: "预计所需数量(按基础数量)",
                  templet: admin.setTableInput(
                    "quantity",
                    nowData.eventName === "detail",
                    "quantity"
                  ),
                },
                { field: "productDetailId", title: "物料ID", hide: true },
                {
                  align: "center",
                  toolbar: "#skuTableBar",
                  title: "操作",
                  width: 100,
                },
              ],
            ],
            done: function () {
              let list = table.cache["skuTable"];
              let productProjectTableList = table.cache["productProjectTable"];
              if (productProjectTableIndex >= 0) {
                productProjectTableList[
                  productProjectTableIndex
                ].versionSkuList = list;
                table.reload("productProjectTable", {
                  data: productProjectTableList,
                });
              }
              admin.tableInputChangeByClass("skuTable", "quantity", (index) => {
                let productProjectTableList =
                  table.cache["productProjectTable"];
                let list = table.cache["skuTable"];
                let quantity = list[index].quantity;
                productProjectTableList[
                  productProjectTableIndex
                ].versionSkuList[index].quantity = quantity;
                table.reload("productProjectTable", {
                  data: productProjectTableList,
                });
              });
            },
          });
          table.on("tool(skuTable)", function (obj) {
            if (obj.event === "del") {
              let index = $(obj.tr[0]).data("index");
              let list = table.cache["skuTable"];
              list.splice(index, 1);
              table.reload("skuTable", { data: list });
            }
          });
          $("#addSku").click(function () {
            admin.formOpen({
              area: "90%",
              offset: "50px",
              title: "配置物料清单",
              path: "components/purchase/skuTableForm.html",
              success: function () {
                parentData.notInListIds = table.cache["skuTable"]
                  .map((v) => v.productDetailId)
                  .join(",");
              },
              end: function () {
                if (childData.list) {
                  const newData = childData.list || [];
                  const oldData = table.cache["skuTable"];
                  console.log(newData, oldData);
                  const list = [...oldData, ...newData];
                  table.reload("skuTable", {
                    data: list, // 设置新的数据
                  });
                }
              },
            });
          });
          //如果为空查询关联的
          if (Array.isArray(testItemData) && testItemData.length === 0) {
            admin.req(
              "enterprise/product/admin/productItem/listByType",
              { productType: res.data.productTypeId },
              function (res) {
                if (res.code == 200) {
                  testItemData = res.data;
                }
                //初始化质检标准表
                table.render({
                  elem: "#testItemTable",
                  data: testItemData,
                  id: "testItemTable",
                  limit: 9999,
                  cols: [
                    [
                      { type: "numbers", title: "序号" },
                      {
                        field: "name",
                        edit: "text",
                        align: "center",
                        title: "检查项",
                      },
                      {
                        field: "standard",
                        edit: "text",
                        sort: true,
                        title: "标准",
                      },
                      {
                        field: "utensil",
                        edit: "text",
                        sort: true,
                        title: "器具",
                      },
                      { field: "way", edit: "text", sort: true, title: "方法" },
                      {
                        field: "importance",
                        edit: "text",
                        sort: true,
                        title: "重要程度",
                      },
                      {
                        field: "detectionRate",
                        edit: "text",
                        sort: true,
                        title: "检测率",
                      },
                      {
                        align: "center",
                        toolbar: "#testItemTableBar",
                        title: "操作",
                        width: 100,
                      },
                    ],
                  ],
                });
              }
            );
          } else {
            //初始化质检标准表
            table.render({
              elem: "#testItemTable",
              data: testItemData,
              id: "testItemTable",
              limit: 9999,
              cols: [
                [
                  { type: "numbers", title: "序号" },
                  {
                    field: "name",
                    edit: "text",
                    align: "center",
                    title: "检查项",
                  },
                  {
                    field: "standard",
                    edit: "text",
                    sort: true,
                    title: "标准",
                  },
                  { field: "utensil", edit: "text", sort: true, title: "器具" },
                  { field: "way", edit: "text", sort: true, title: "方法" },
                  {
                    field: "importance",
                    edit: "text",
                    sort: true,
                    title: "重要程度",
                  },
                  {
                    field: "detectionRate",
                    edit: "text",
                    sort: true,
                    title: "检测率",
                  },
                  {
                    align: "center",
                    toolbar: "#testItemTableBar",
                    title: "操作",
                    width: 100,
                  },
                ],
              ],
            });
          }

          //初始化 bom
          // 渲染表格
          let bomTree = tableTree.render(
            {
              id: "#bomTreeTableInfo",
              elem: "#bomTreeTableInfo",
              url:
                config.base +
                "enterprise/res/admin/planning/proBom/bomTree/" +
                data.productDetailId,
              page: false,
              cellMinWidth: 100,
              where: { limit: 9999 },
              cols: [
                [
                  { type: "numbers", title: "序号", fixed: "left" },
                  { field: "productName", sort: true, title: "BOM产品名称" },
                  { field: "productCode", sort: true, title: "产品编号" },
                  { field: "productSpec", sort: true, title: "规格码" },
                  { field: "productTypeName", sort: true, title: "物资类别" },
                  {
                    field: "assemblyNatureName",
                    sort: true,
                    title: "产品性质",
                  },
                  {
                    field: "inSkuUnitName",
                    sort: true,
                    title: "计量单位",
                    width: 90,
                  },
                  {
                    field: "inUnitCount",
                    edit: nowData.eventName === "detail" ? false : "text",
                    sort: true,
                    title: "需求数",
                    width: 80,
                  },
                  {
                    field: "remark",
                    edit: nowData.eventName === "detail" ? false : "text",
                    sort: true,
                    title: "描述",
                  },
                  {
                    align: "center",
                    toolbar: "#bomProductPlanningTableBar",
                    hide: nowData.eventName === "detail",
                    title: "操作",
                    width: 240,
                  },
                ],
              ],
            },
            { keyPid: "parentId", title: "productName" }
          );
          form.render(); //菜单渲染 把内容加载进去

          //addBomSKu 添加子件物料的点击事件
          $("#addBomSKu").click(function () {
            showSkuListInfo(data.productDetailId, data.skuCode, "1", "");
          });

          // 工具条点击事件
          table.on("tool(bomTreeTableInfo)", function (obj) {
            if (obj.event === "addDownInfo") {
              //添加下级
              //addDownInfo
              showSkuListInfo(
                obj.data.id,
                obj.data.productCode,
                "2",
                obj.data.bomId
              );
            } else if (obj.event === "removeInfo") {
              //移除
              //removeInfo
              removeSkuInfo(obj.data.bomId);
            }
          });

          // 显示编辑弹窗
          function showSkuListInfo(productDetailId, skuCode, flag, bomId) {
            let title = "客户产品规划管理";
            let parentInfo = {};
            parentInfo.productDetailId = productDetailId;
            parentInfo.flag = flag;
            parentInfo.skuCode = skuCode;
            parentInfo.bomId = bomId;
            admin.putTempData("bomSkuData", parentInfo);
            admin.formOpen({
              type: 1,
              area: ["1480px", "90%"],
              style: "font-size: 20px;",
              title: title,
              path: "components/res/planning/skuDetailResearchForm.html",
              end: function () {
                bomTree.reload({}, "data");
              },
            });
          }
        } else {
          layer.msg(res.msg, { icon: 2 });
        }
      });

      // 查看附件
      function showViewAttachmentModel2(data) {
        admin.open({
          type: 1,
          area: ["65%", "900px"],
          offset: "35px",
          title: "修改图纸",
          content: $("#viewAttachmentHtml2").html(),
          success: function () {
            console.log("data=>", data);
            if (data.attachment && data.attachment.indexOf(".pdf") !== -1) {
              PDFObject.embed(data.attachment, "#example1");
            } else {
              let attachmentHtml = "";
              data.attachment.split(",").forEach((attachmentUrl, index) => {
                attachmentHtml +=
                  '<div><img style="max-width: 900px;max-height: 650px" src="' +
                  attachmentUrl +
                  '"></div>';
              });
              $("#example1").html(attachmentHtml);
            }

            //赋值remark
            $("#processDescription").val(data.remark);

            $("#productPicBtn").click(
              uploadImg("productPicBtn", "example1", "productPic")
            );

            //保存的点击事件
            form.on("submit( )", function (d) {
              layer.load(2);
              let params = {};
              params.type = "2";
              params.taskId = data.taskId;
              params.remark = $("#processDescription").val();
              params.drawId = data.drawId;
              params.fileUrl = $("#productPic").val();
              params.name = newFileName;
              //新增修改
              admin.req(
                "enterprise/res/admin/proDraw/updateDrawVersion",
                JSON.stringify(params),
                function (res) {
                  layer.closeAll("loading");
                  if (res.code == 200) {
                    layer.msg(res.msg, { icon: 1 });
                    layer.closeAll("page");
                  } else {
                    layer.msg(res.msg, { icon: 2 });
                  }
                },
                "POST",
                true,
                "application/json; charset=utf-8"
              );
            });
          },
        });
      }

      let newFileName = "";

      // 上传文件
      /*
       * _elem: 上传按钮的名字,
       * pathId: 显示图片容器的名字,
       * inputId: 提交文件路径元素的名字,
       * isMultiple: 是不是多文件(单文件为空或者false,多文件true)
       *
       * */
      function uploadImg(_elem, pathId, inputId, isMultiple) {
        upload.render({
          elem: "#" + _elem,
          url: config.upload_url + "uploadFile",
          data: {},
          accept: "file",
          exts: "jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx",
          headers: { Authorization: "Bearer " + config.getToken() },
          done: function (res) {
            if (res.code == 200) {
              layer.msg(res.msg || "上传成功", { icon: 1 });
              let imagUrl = res.data.url;
              newFileName = res.data.fileName;
              if (isMultiple == true) {
                $("#" + pathId).append(
                  '<img style="max-width: 900px;max-height: 650px" src="' +
                    imagUrl +
                    '"/>'
                );
                $("#" + inputId).val(imagUrl);
              } else {
                $("#" + pathId).html(
                  '<img style="max-width: 900px;max-height: 650px" src="' +
                    imagUrl +
                    '"/>'
                );
                $("#" + inputId).val(imagUrl);
              }
            } else if (res.code == 502) {
              return location.replace("admin/login.html");
            } else {
              layer.msg(res.msg || "上传失败", { icon: 2 });
            }
          },
        });
      }

      //移除下级物料
      function removeSkuInfo(bomId) {
        layer.confirm(
          "确认要移除该子件吗？",
          {
            offset: "65px",
            skin: "layui-layer-admin",
          },
          function (i) {
            layer.close(i);
            layer.load(2);
            //添加bom子件信息
            admin.req(
              "enterprise/res/admin/planning/proBom/deleteBom/" + bomId,
              {},
              function (res) {
                layer.closeAll("loading");
                if (res.code == 200) {
                  layer.msg(res.msg, { icon: 1 });
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              "DELETE"
            );
          }
        );
      }

      //下拉款的选择事件
      form.on("select(processLineTemplate)", function (data) {
        let id = data.value;
        table.reload("productProjectTable", {
          data: [],
        });
        if (id) {
          //查询工艺模板关联的工序
          admin.req(
            "enterprise/product/admin/processLineTemplate/listAndProcess",
            {
              // sort: "sort_number",
              // order: "asc",
              templateId: id,
              id: data.value,
              page: 1,
              limit: 9999,
              type: 1,
            },
            function (res) {
              if (res.code == 200) {
                let processes = res.data;
                projectTableData = processes.map((v) => {
                  return {
                    name: v.nodeNames,
                    proCode: $("#inSkuName").val() + "-" + v.sortNumber,
                    sorted: v.sortNumber,
                    content: v.remark,
                    qualityParam: "",
                    fixture: "",
                    measuringTools: "",
                    hoursQuota: "",
                    salaryQuota: "",
                    chengpin: "",

                    // skuGetCode: ""
                  };
                });
                table.reload("productProjectTable", {
                  data: projectTableData,
                });
              }
            }
          );
        }
      });

      //如果产品属性是加工件 就只有工序
      // if (data.assemblyNatureId === "3") {
      //     bom_tab.style.display = 'none';
      //     bom_content.style.display = 'none';
      //     //加载工序模板
      // admin.initDataSelect('enterprise/product/admin/processLineTemplate/list?page=1&limit=999', null, 'processLineTemplate', null, '模板', 'name', 'id');
      // } else {
      //     gx_tab.style.display = 'none';
      //     gx_content.style.display = 'none';
      // }

      //移除某一行
      table.on("tool(productProjectTable)", function (obj) {
        if (obj.event === "delProcess") {
          // //删除
          // obj.del(); // 删除当前行
          // // 获取表格数据
          // projectTableData = table.cache['productProjectTable'];
          // projectTableData = projectTableData.filter((item) => Object.keys(item).length > 0);
          // table.reload('productProjectTable', {
          //   data: projectTableData,
          // });
          obj.del(); // 删除当前行
          // 获取表格数据
          projectTableData = projectTableData.filter(
            (item) => Object.keys(item).length > 0
          );
          // projectTableData = table.cache['productProjectTable'];
          // console.log('projectTableData=>', projectTableData);

          table.reload("productProjectTable", {
            data: projectTableData,
          });
        } else if (obj.event === "checkSku") {
          let skuSelectModel = admin.formOpen({
            type: 1,
            area: ["1480px", "90%"],
            style: "font-size: 20px;",
            title: "客户产品规划管理",
            content: $("#skuSelectDiv").html(),
          });
          table.render({
            id: "skuSelectTable",
            elem: "#skuSelectTable",
            url: config.base + "enterprise/product/admin/productDetailWMS/list",
            page: true,

            where: {
              categoryType: "production",
            },
            cols: [
              [
                { type: "radio", title: "选择", width: 60 },
                { type: "numbers", title: "序号", align: "center", width: 60 },
                {
                  field: "skuCode",
                  align: "center",
                  title: "物料编码",
                  width: 120,
                },
                {
                  field: "skuName",
                  align: "center",
                  title: "物料名称",
                  width: 120,
                },
                {
                  field: "productTypeName",
                  align: "center",
                  title: "物资类别",
                  width: 120,
                },
                {
                  field: "productCategoryId",
                  align: "center",
                  title: "自定义分类",
                  width: 120,
                },
                {
                  field: "isDeleted",
                  align: "center",
                  title: "状态",
                  width: 120,
                  templet: function (d) {
                    return d.isDeleted ? "停用" : "正常";
                  },
                },
                {
                  field: "createTime",
                  align: "center",
                  title: "创建时间",
                  width: 120,
                },
                {
                  field: "modifierName",
                  align: "center",
                  title: "创建人",
                  width: 120,
                },
              ],
            ],
          });
          $("#skuSelectConfirm").click(function () {
            //获取选中的skuCode
            let skuObj = table.checkStatus("skuSelectTable").data[0];
            if (skuObj) {
              // parent.valueSkuObj(skuObj);
              console.log("obj=>", obj);
              console.log("skuObj=>", skuObj);
              // 让列表当前这一行的productDetailId等于skuObj.id
              const index = $(obj.tr[0]).data("index");
              table.cache["productProjectTable"][index].productDetailId =
                skuObj.id;
              table.cache["productProjectTable"][index].skuCode =
                skuObj.skuCode;
              table.reload("productProjectTable", {
                data: table.cache["productProjectTable"],
              });
              layer.close(skuSelectModel);
            } else {
              layer.msg("请选择物料", { icon: 2, time: 1000 });
            }
          });
        }
      });

      //移除某一行
      table.on("tool(testItemTable)", function (obj) {
        if (obj.event === "delTestItem") {
          //删除
          obj.del(); // 删除当前行
          // 获取表格数据
          testItemData = table.cache["testItemTable"];
          testItemData = testItemData.filter(
            (item) => Object.keys(item).length > 0
          );
          table.reload("testItemTable", {
            data: data,
          });
        }
      });

      // 上传附件-pdf
      upload.render({
        elem: "#fileUploadMoldBtn",
        url: config.upload_url + "uploadFile",
        data: {},
        accept: "file",
        exts: "jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx",
        headers: { Authorization: "Bearer " + config.getToken() },
        done: function (res) {
          if (res.code == 200) {
            layer.msg(res.msg || "上传成功", { icon: 1 });
            let imagUrl = res.data.url;
            moldName = res.data.fileName;
            fileName = res.data.fileName;
            $("#addMoldHeaderPdf").html(
              '<div class="moldAttachments">' +
                '<div><img name="moldAttachments" src="../../../admin/assets/images/attachmentsIcon/pdf.png"><span class="file-a">' +
                moldName +
                "</span></div></div>"
            );
            $("#attachmentMoldPdf").val(imagUrl);

            $(".moldAttachments").click(function () {
              let json = {};
              json.attachment = imagUrl;
              showViewAttachmentModel(json);
            });
          } else if (res.code == 502) {
            return location.replace("admin/login.html");
          } else {
            layer.msg(res.msg || "上传失败", { icon: 2 });
          }
        },
      });

      /**
       * 添加
       */
      $("#addProcessOne").click(function () {
        let newRow = {
          name: "",
          proCode: "",
          sorted: "",
          content: "",
          qualityParam: "",
          // skuGetCode: ""
        };
        // projectTableData = table.cache['productProjectTable'].push(newRow);
        projectTableData.push(newRow);
        table.reload("productProjectTable", {
          data: projectTableData,
        });
      });

      //addTestItem
      $("#addTestItem").click(function () {
        let newRow = {
          name: "",
          standard: "",
          utensil: "",
          way: "",
          importance: "",
          detectionRate: "",
        };
        testItemData.push(newRow);
        table.reload("testItemTable", {
          data: testItemData,
        });
      });

      //保存检测项点击
      $("#saveTestItem").click(function () {
        let param = {};
        param.skuCode = $("#inSkuCode").val();
        param.productDetailId = $("#productDetailId").val();
        let listInfo = table.cache["testItemTable"];
        let testItemData = [];
        if (Array.isArray(listInfo) && listInfo.length !== 0) {
          listInfo.forEach((item) => {
            let info = {};
            info.name = item.name;
            info.standard = item.standard;
            info.utensil = item.utensil;
            info.way = item.way;
            info.importance = item.importance;
            info.detectionRate = item.detectionRate;
            testItemData.push(info);
          });
        }
        param.testItemData = testItemData;
        admin.req(
          "enterprise/res/admin/planning/proTask/addSkuQuality",
          JSON.stringify(param),
          function (res) {
            layer.closeAll("loading");
            if (res.code == 200) {
              layer.msg(res.msg, { icon: 1 });
            } else {
              layer.msg(res.msg, { icon: 2 });
            }
          },
          "POST",
          true,
          "application/json; charset=utf-8"
        );
      });

      //保存按钮的点击事件
      $("#saveProjectUp").click(function () {
        let param = {};
        param.templateId = $("#processLineTemplate").val();
        param.skuCode = $("#inSkuCode").val();
        param.tzId = tzId;
        param.tzVersion = tzVersion;
        param.isRelevance = $("#isRelevance").val();
        param.mainSkuId = $("#mainSkuId").val();
        param.productDetailId = $("#productDetailId").val();
        param.fileUrl = $("#attachmentMoldPdf").val();
        param.moldName = moldName;
        param.moldRemark = $("#moldRemark").val();
        let listInfo = table.cache["productProjectTable"];
        let processProjectData = [];
        if (Array.isArray(listInfo) && listInfo.length !== 0) {
          listInfo.forEach((item) => {
            let info = {};
            info.name = item.name;
            info.content = item.content;
            info.proCode = item.proCode;
            info.qualityParam = item.qualityParam;
            info.sorted = item.sorted;
            processProjectData.push(info);
          });
        }
        param.projectTableData = processProjectData;
        admin.req(
          "enterprise/res/admin/planning/proTask/addSkuProcess",
          JSON.stringify(param),
          function (res) {
            layer.closeAll("loading");
            if (res.code == 200) {
              layer.msg(res.msg, { icon: 1 });
            } else {
              layer.msg(res.msg, { icon: 2 });
            }
          },
          "POST",
          true,
          "application/json; charset=utf-8"
        );
      });

      //提交校对的点击事件
      $("#submitProofread").click(async function () {
        let formData = {
          drawInfo: {},
        };
        const res = await admin.reqPro(
          "enterprise/res/admin/planning/proTask/detail/" + data.id
        );
        let resData = res.data;
        console.log("res=>", resData);
        formData.drawInfo.id = resData.drawInfo?.id;
        formData.tzId = resData.drawInfo?.id;
        formData.templateId = $("#processLineTemplate").val();
        formData.isRelevance = $("#isRelevance").val();
        formData.moldName = fileName;
        formData.fileUrl = $("#attachmentMoldPdf").val();
        formData.moldRemark = $("#moldRemark").val();
        formData.taskId = data.id;
        formData.projectTableData = table.cache["productProjectTable"];
        console.log("formData=>", formData);
        if (formData.projectTableData.length > 0) {
          admin.req(
            "enterprise/res/admin/planning/proTask/addSkuProcess",
            JSON.stringify(formData),
            function (res) {
              layer.closeAll("loading");
              if (res.code == 200) {
                layer.msg(res.msg, { icon: 1 });
                table.reload("productTaskTableInfo", {});
                layer.closeAll("page");
              } else {
                layer.msg(res.msg, { icon: 2 });
              }
            },
            "POST",
            true,
            "application/json; charset=utf-8"
          );
        } else {
          layer.msg("最少添加一个工序", { icon: 2 });
        }
        // let id = data.id;
        // admin.req(
        //   'enterprise/res/admin/planning/proTask/submitProofread/' + id,
        //   {},
        //   function (res) {
        //     layer.closeAll('loading');
        //     if (res.code == 200) {
        //       layer.msg(res.msg, { icon: 1 });
        //       table.reload('productTaskTableInfo', {});
        //       layer.closeAll('page');
        //     } else {
        //       layer.msg(res.msg, { icon: 2 });
        //       layer.closeAll('page');
        //     }
        //   },
        //   'POST',
        // );
      });

      // 查看附件
      function showViewAttachmentModel(data) {
        admin.open({
          type: 1,
          area: ["60%", "80%"],
          offset: "65px",
          title: "查看附件",
          content: $("#viewAttachmentHtml").html(),
          success: function () {
            if (data.attachment && data.attachment.indexOf(".pdf") !== -1) {
              PDFObject.embed(data.attachment, "#example1");
            } else {
              var attachmentHtml = "";
              data.attachment.split(",").forEach((attachmentUrl, index) => {
                attachmentHtml +=
                  '<div><div><img src="' + attachmentUrl + '"></div></div>';
              });
              $("#example1").html(attachmentHtml);
            }
          },
        });
      }
    }
  );
</script>
